package com.zj.study.utils.validation.validator.time;


import com.zj.study.utils.validation.annotation.constraint.FutureOrPresent;
import com.zj.study.utils.validation.validator.ConstraintValidator;
import org.springframework.lang.NonNull;
import org.springframework.lang.Nullable;

/**
 * @author 谭耀飞
 * @since 2020.11.0
 */
public abstract class AbstractFutureOrPresentValidator<T> implements
    ConstraintValidator<FutureOrPresent, T> {

  @Override
  public boolean isValid(@NonNull FutureOrPresent futureOrPresent, @Nullable T value) {
    return value == null || compare(value);
  }

  /**
   * 比较值
   *
   * @param value 值
   * @return 校验是否通过
   */
  abstract boolean compare(@NonNull T value);

}
